<?php
/*******************************************************************************
 *
 *  Name: viewreportsview
 *
 *  Date: 05/03/2012
 *  
 *  Description: shows reports in a table format to an analyst
 *  
 *  Author: Hayden Waisanen
 *  
 *  Todo:
 *     NONE
 *
 *  Modification History:  
 * 
 *   Date         Name
 *  ----------   --------------
 *  2012-04-25   HAYDEN WAISANEN
 *  2012-04-23   HAYDEN WAISANEN
 *  2012-04-22   HAYDEN WAISANEN
 *  2012-04-17   HAYDEN WAISANEN
 *  2012-04-17   HAYDEN WAISANEN
 * 
 *****************************************************************************/
?>
<h4><?php echo $title; ?></h4>
<?php if(!isset($format)): ?>
<table border="2px"> 
<tr>
<td>ReportID</td>
<td>CR ID</td>
<td>Location</td>
<td>Report Time</td>
<td>View</td>
</tr>
<?php
foreach ($entries as $entry)
{
   echo "<tr>";
   echo '<td>'.$entry["ReportID"].'</td>';
   echo '<td>'.$entry["CustomerRepID"].'</td>';
   echo '<td>'.$entry["City"].', '.$entry["State"] .'</td>';
   echo '<td>'.$entry["ReportTime"].'</td>';
   echo '<td>'.anchor('analyst/viewreport/'.$entry["ReportID"].'/',"View") .'</td>';
   echo "<tr>";
}
?>
</table>
<?php endif; 
if( isset($format)):

//Format struct
 //$format = array('header1' = array("human_readable"=> "Human Readable", "formatstring" => "formatstring text", "formatparams" => array('arg1','arg2'))
 //vprintf("formatstring", array('1','1'))
 //array_values(array)
   ?>

<table border="2px"> 
<tr>
<?php 
foreach($format as $header => $value)
{
   if(array_key_exists('human_readable',$value))
      echo "<td>".$value["human_readable"]."</td>"; 
   else
      echo "<td>".$header."</td>"; 
}
?>
<?php
foreach($entries as $entry)
{
   echo "<tr>";
   foreach($format as $header => $values)
   {
      echo "<td>";
      if(array_key_exists('formatstring',$values))
      {
         $params = array();
         foreach($values["formatparams"] as $param)
         {
            array_push($params, $entry[$param]);
         }
         if(array_key_exists('link', $values))
         {
            echo anchor(vsprintf($values["formatstring"],$params), $values["link"]);
            
         }
         else
         {
            vprintf($values["formatstring"],$params);
         }
      }
      else
      {
         echo $entry[$header];
      }
      echo "</td>";
         
   }
   echo "</tr>";
}
?>
</table>


<?php endif; ?>
